#include "MultiStart.hpp"
#include <cstdlib>

void	MultiStart::execute() EXC_THROWER()
{
	EXC_RETHROW_BEGIN()
	{
		unsigned	iteration = 0;
		unsigned	amelioration_iteration = 0;
		unsigned	r1 = 0;
		unsigned	r2 = 0;
		
		ntSolution.complete();
		ntSolution.eval(&ntBestSolEval);
		ntSolEval = ntBestSolEval;
		ntBestSolution = ntSolution;
		goto coucou;
		
		for (;; iteration++)
		{
			// build
			//ntSolver.setMaxIt(10);
			//ntSolver.execute();
			
			//ntSolution = ntSolver.getBestSolution();
			
			ntSolution.reorganize();
			for (unsigned i = 0 ; i < ntSolEval.seNTournees ; i++)
			{
				for (unsigned j = 0 ; j < ntSolEval.seNTournees ; j++)
				{
					if (i == j)
					{
						continue;
					}
					
					localVND2(ntSolution[i], ntSolution[j], 1);
					ntSolution.validateTournee(i);
					ntSolution.validateTournee(j);
				}
			}
			
			ntSolution.eval(&ntSolEval);
			
			if (ntSolEval < ntBestSolEval)
			{
				ntBestSolution = ntSolution;
				ntBestSolEval = ntSolEval;
				
				std::cout << ntSolution.toString() << std::endl;
				std::cout << ntSolEval.toString() << std::endl;
coucou:
				
				/*if (iteration == 100)
					continue;*/
				ntSolver.setMaxIt((iteration - amelioration_iteration) * 10);
				
				//ntSolution.fillDeque(ntSolver.getMerger().getTable());
				ntSolver.execute();
				ntSolution = ntSolver.getBestSolution();
				
				ntSolution.eval(&ntSolEval);
				if (ntSolEval < ntBestSolEval)
				{
					ntBestSolEval = ntSolEval;
					ntBestSolution = ntSolution;
				}
				else
					ntSolution = ntBestSolution;
					
				amelioration_iteration = iteration;
			}
			else
			{
				ntSolution = ntBestSolution;
			}
			
		}
	}
	EXC_RETHROW_END()
}
